package com.bdqn.demo.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class MybatisUtil {
    static SqlSessionFactory sqlSessionFactory;
    static{
        InputStream inputStream=MybatisUtil.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
        sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
    }
    //获取SqlSession连接
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }
    //关闭SqlSession
    public static void closeSqlSession(SqlSession sqlSession){
        sqlSession.close();
    }
}
